#define _CRT_SECURE_NO_WARNINGS

#include "SList.h"

//int main()
//{
//	SLTNode* plist = NULL;
//	SLTPushFront(&plist, 1);
//	SLTPushFront(&plist, 2);
//	SLTPushFront(&plist, 3);
//	SLTPushFront(&plist, 4);
//
//
//	SLTPushBack(&plist, 5);
//
//
//	
//	
//
//
//	SLTNode* ret = SLTFind(&plist, 4);
//	SLTInsertBack(&plist, ret, 10);
//	SLTPrint(&plist);
//
//	return 0;
//}
#include <stdbool.h>
typedef struct SListNode ListNode;

bool chkPalindrome(ListNode* A)
{
    ListNode* fast = A;
    ListNode* slow = A;
    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
    }
    ListNode* n1 = NULL;
    ListNode* n2 = slow;
    ListNode* n3 = slow->next;
    while (n2)
    {
        n2->next = n1;
        n1 = n2;
        n2 = n3;
        if (n3)
            n3 = n3->next;
    }
    while (n1)
    {
        if (n1->data != A->data)
            return false;
        n1 = n1->next;
        A = A->next;
    }
    return true;
}

ListNode* partition(ListNode* phead, int x)
{
    ListNode* pcur = phead;
    ListNode* lesshead = (ListNode*)malloc(sizeof(ListNode));
    ListNode* largehead = (ListNode*)malloc(sizeof(ListNode));
    ListNode* lesstail = lesshead;
    ListNode* largetail = largehead;
    while (pcur)
    {
        if (pcur->data > x)
        {
            largetail->next = pcur;
            largetail = pcur;
        }
        else
        {
            lesstail->next = pcur;
            lesstail = pcur;
        }
        pcur = pcur->next;
    }
    largetail->next = lesstail->next = NULL;
    lesstail->next = largehead->next;
    return lesshead->next;
}



int main()
{
    SLTNode* plist = NULL;
    SLTPushBack(&plist, 1);
    SLTPushBack(&plist, 3);
    SLTPushBack(&plist, 4);
    SLTPushBack(&plist, 0);
    ListNode* ret = partition(plist, 2);

	return 0;
}